unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGridEh, StdCtrls, DB, ADODB;

type
  TForm2 = class(TForm)
    DBGridEh1: TDBGridEh;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    Button1: TButton;
    Button2: TButton;
    DBGridEh2: TDBGridEh;
    DBGridEh3: TDBGridEh;
    Label1: TLabel;
    Label2: TLabel;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    ADOQuery4: TADOQuery;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}
uses
  Unit1;
procedure TForm2.FormCreate(Sender: TObject);
begin
  ADOQuery1.Close;
  ADOQuery1.Open;
  DBGridEh1.Refresh;
  ADOQuery2.Close;
  ADOQuery2.Open;
  ADOQuery2.Last;

  ADOQuery3.Close;
  ADOQuery3.Open;
  ADOQuery3.Last;

end;

procedure TForm2.Button1Click(Sender: TObject);
var
  str: string;
begin
  if ADOQuery1.RecordCount<1 then
  begin
    Exit;
  end;


  ADOQuery4.SQL.Clear;
  str := 'delete SB_sbbh where sbbh=''' + ADOQuery1.FieldValues['sbdjdm'] + '''';
  ADOQuery4.SQL.Add(str);
  ADOQuery4.ExecSQL;

  ADOQuery4.SQL.Clear;
  str := 'insert into SB_sbbh ( sbbh) values (''' + ADOQuery1.FieldValues['sbdjdm'] + ''')';
  ADOQuery4.SQL.Add(str);
  ADOQuery4.ExecSQL;
  ADOQuery1.Edit;
  ADOQuery1.FieldValues['bfsy'] := '1';
  ADOQuery1.FieldValues['sfwc'] := '1';
  ADOQuery1.Post;

  ADOQuery1.Close;
  ADOQuery1.Open;

  ADOQuery2.Close;
  ADOQuery2.Open;
  ADOQuery2.Last;

  ADOQuery3.Close;
  ADOQuery3.Open;
  ADOQuery3.Last;


end;

procedure TForm2.Button2Click(Sender: TObject);
var
  str: string;
begin
  if ADOQuery1.RecordCount<1 then
  begin
    Exit;
  end;

  ADOQuery4.SQL.Clear;
  str := 'delete SB_sbbh where sbbh=''' + ADOQuery1.FieldValues['sbdjdm'] + '''';
  ADOQuery4.SQL.Add(str);
  ADOQuery4.ExecSQL;
  ADOQuery1.Edit;
  ADOQuery1.FieldValues['bfsy'] := '2';
  ADOQuery1.FieldValues['sfwc'] := '1';
  ADOQuery1.Post;

  ADOQuery1.Close;
  ADOQuery1.Open;

  ADOQuery2.Close;
  ADOQuery2.Open;
  ADOQuery2.Last;

  ADOQuery3.Close;
  ADOQuery3.Open;
  ADOQuery3.Last;



end;

procedure TForm2.Button3Click(Sender: TObject);
var
  str: string;
begin
  if ADOQuery2.RecordCount<1 then
  begin
    Exit;
  end;


  ADOQuery4.SQL.Clear;
  str := 'delete SB_sbbh where sbbh=''' + ADOQuery2.FieldValues['sbdjdm'] + '''';
  ADOQuery4.SQL.Add(str);
  ADOQuery4.ExecSQL;

  ADOQuery2.Edit;
  ADOQuery2.FieldValues['bfsy'] := '0';
  ADOQuery2.FieldValues['sfwc'] := '0';
  ADOQuery2.Post;

  ADOQuery1.Close;
  ADOQuery1.Open;

  ADOQuery2.Close;
  ADOQuery2.Open;
  ADOQuery2.Last;

  ADOQuery3.Close;
  ADOQuery3.Open;
  ADOQuery3.Last;

end;

procedure TForm2.Button4Click(Sender: TObject);
var
  str: string;
begin
  if ADOQuery3.RecordCount<1 then
  begin
    Exit;
  end;


  ADOQuery4.SQL.Clear;
  str := 'delete SB_sbbh where sbbh=''' + ADOQuery3.FieldValues['sbdjdm'] + '''';
  ADOQuery4.SQL.Add(str);
  ADOQuery4.ExecSQL;

  ADOQuery3.Edit;
  ADOQuery3.FieldValues['bfsy'] := '0';
  ADOQuery3.FieldValues['sfwc'] := '0';
  ADOQuery3.Post;

  ADOQuery1.Close;
  ADOQuery1.Open;

  ADOQuery2.Close;
  ADOQuery2.Open;
  ADOQuery2.Last;

  ADOQuery3.Close;
  ADOQuery3.Open;
  ADOQuery3.Last;

end;

end.

